package cn.iocoder.yudao.module.eval.dal.mysql.evaluator;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.eval.controller.admin.evaluator.vo.EvalEvaluatorQualificationPageReqVO;
import cn.iocoder.yudao.module.eval.dal.dataobject.evaluator.EvalEvaluatorQualificationDO;
import org.apache.ibatis.annotations.Mapper;

import java.time.LocalDate;
import java.util.Collection;
import java.util.List;

/**
 * 考评员资质 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface EvalEvaluatorQualificationMapper extends BaseMapperX<EvalEvaluatorQualificationDO> {

    default PageResult<EvalEvaluatorQualificationDO> selectPage(EvalEvaluatorQualificationPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<EvalEvaluatorQualificationDO>()
                .eqIfPresent(EvalEvaluatorQualificationDO::getUserId, reqVO.getUserId())
                .likeIfPresent(EvalEvaluatorQualificationDO::getProfessionCodes, reqVO.getProfessionCode())
                .likeIfPresent(EvalEvaluatorQualificationDO::getSkillLevels, reqVO.getSkillLevel())
                .likeIfPresent(EvalEvaluatorQualificationDO::getSkillLevels, reqVO.getQualificationLevel())
                .eqIfPresent(EvalEvaluatorQualificationDO::getQualificationStatus, reqVO.getQualificationStatus())
                .likeIfPresent(EvalEvaluatorQualificationDO::getCertificateNumber, reqVO.getCertificateNumber())
                .betweenIfPresent(EvalEvaluatorQualificationDO::getCertificateDate, reqVO.getCertificateDate())
                .betweenIfPresent(EvalEvaluatorQualificationDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(EvalEvaluatorQualificationDO::getId));
    }

    default PageResult<EvalEvaluatorQualificationDO> selectPageByUserIds(EvalEvaluatorQualificationPageReqVO reqVO, Collection<Long> userIds) {
        return selectPage(reqVO, new LambdaQueryWrapperX<EvalEvaluatorQualificationDO>()
                .in(EvalEvaluatorQualificationDO::getUserId, userIds)
                .likeIfPresent(EvalEvaluatorQualificationDO::getProfessionCodes, reqVO.getProfessionCode())
                .likeIfPresent(EvalEvaluatorQualificationDO::getSkillLevels, reqVO.getSkillLevel())
                .likeIfPresent(EvalEvaluatorQualificationDO::getSkillLevels, reqVO.getQualificationLevel())
                .eqIfPresent(EvalEvaluatorQualificationDO::getQualificationStatus, reqVO.getQualificationStatus())
                .likeIfPresent(EvalEvaluatorQualificationDO::getCertificateNumber, reqVO.getCertificateNumber())
                .betweenIfPresent(EvalEvaluatorQualificationDO::getCertificateDate, reqVO.getCertificateDate())
                .betweenIfPresent(EvalEvaluatorQualificationDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(EvalEvaluatorQualificationDO::getId));
    }

    default EvalEvaluatorQualificationDO selectByUserId(Long userId) {
        return selectOne(EvalEvaluatorQualificationDO::getUserId, userId);
    }

    default List<EvalEvaluatorQualificationDO> selectListByUserIds(Collection<Long> userIds) {
        return selectList(new LambdaQueryWrapperX<EvalEvaluatorQualificationDO>()
                .in(EvalEvaluatorQualificationDO::getUserId, userIds));
    }

    default List<EvalEvaluatorQualificationDO> selectListByQualificationStatus(Integer qualificationStatus) {
        return selectList(EvalEvaluatorQualificationDO::getQualificationStatus, qualificationStatus);
    }

    default EvalEvaluatorQualificationDO selectByCertificateNumber(String certificateNumber) {
        return selectOne(EvalEvaluatorQualificationDO::getCertificateNumber, certificateNumber);
    }

    default List<EvalEvaluatorQualificationDO> selectList(EvalEvaluatorQualificationPageReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<EvalEvaluatorQualificationDO>()
                .eqIfPresent(EvalEvaluatorQualificationDO::getUserId, reqVO.getUserId())
                .likeIfPresent(EvalEvaluatorQualificationDO::getProfessionCodes, reqVO.getProfessionCode())
                .likeIfPresent(EvalEvaluatorQualificationDO::getSkillLevels, reqVO.getSkillLevel())
                .eqIfPresent(EvalEvaluatorQualificationDO::getQualificationStatus, reqVO.getQualificationStatus())
                .likeIfPresent(EvalEvaluatorQualificationDO::getCertificateNumber, reqVO.getCertificateNumber())
                .betweenIfPresent(EvalEvaluatorQualificationDO::getCertificateDate, reqVO.getCertificateDate())
                .betweenIfPresent(EvalEvaluatorQualificationDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(EvalEvaluatorQualificationDO::getId));
    }

    default Long selectCountByQualificationStatus(Integer qualificationStatus) {
        return selectCount(EvalEvaluatorQualificationDO::getQualificationStatus, qualificationStatus);
    }

    default Long selectCountByValidUntilBetween(LocalDate startDate, LocalDate endDate) {
        return selectCount(new LambdaQueryWrapperX<EvalEvaluatorQualificationDO>()
                .between(EvalEvaluatorQualificationDO::getValidUntil, startDate, endDate));
    }

    default Long selectCountByValidUntilBefore(LocalDate date) {
        return selectCount(new LambdaQueryWrapperX<EvalEvaluatorQualificationDO>()
                .lt(EvalEvaluatorQualificationDO::getValidUntil, date));
    }

}
